/*
 * CrystalAnalysis.cpp
 *
 *  Created on: Aug 6, 2012
 *      Author: koschke
 */

#include "CrystalAnalysis.h"
#include "CrystalAnalysisWorker.h"
#include <votca/csg/csgapplication.h>
#include <stdio.h>

CrystalAnalysis::CrystalAnalysis() {
}

CrystalAnalysis::~CrystalAnalysis() {
}

void CrystalAnalysis::Initialize() {
	CsgApplication::Initialize();

	AddProgramOptions("options")("c",
			boost::program_options::value<double>()->default_value(0.0),
			"cut-off for nearest neighbor search");
	AddProgramOptions("options")("t",
			boost::program_options::value<double>()->default_value(0.7),
			"threshold for the classification of liquid/solid atoms");
}

/* check for sane input */
void CrystalAnalysis::BeginEvaluate(Topology* top, Topology* top_ref) {
	if (OptionsMap()["c"].as<double>() <= 0.0) {
		printf("Please provide the cut-off distance\n"); //TODO replace by runtime error/exception
		exit(1);
	}
}

//TODO I don't want any input variables in the worker class...
CsgApplication::Worker* CrystalAnalysis::ForkWorker(void) {
	CrystalAnalysisWorker *worker;
	worker = new CrystalAnalysisWorker(OptionsMap()["c"].as<double>(), OptionsMap()["t"].as<double>());

	return worker;
}

/* any wanted output should be put here */
void CrystalAnalysis::MergeWorker(Worker* worker) {
	CrystalAnalysisWorker * myWorker;
	myWorker = dynamic_cast<CrystalAnalysisWorker*>(worker);
	myWorker->orderParameter->PrintInfo();

//TODO check if all 'new's are deleted...
}

void CrystalAnalysis::EndEvaluate() {
}

